package CommentTable;

import comment.Comment;
import page.PageClass;
import utils.JdbcUtils;

import javax.swing.*;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

public class QueryComment {
    public static void init(){
        JFrame frame=new JFrame();
        String info = JOptionPane.showInputDialog(frame,"要查寻的id编号为:","输入",JOptionPane.WARNING_MESSAGE);
        if(!info.isEmpty()){
            JOptionPane.showMessageDialog(frame,"查询成功");
            int id = 0;
            String text = null;
            LocalDateTime timebe=null;
            LocalDateTime timeen=null;
            int agree=0;
            int disagree=0;
            String user=null;
            String name=null;
            List<Map<String, Object>> datas= JdbcUtils.JdbcQuery(Comment.sql_queryComment,info);
            for(Map<String,Object> map : datas){
                for(String key : map.keySet()) {
                    if(key.equals("comment_id"))id= (int) map.get(key);
                    if(key.equals("comment_text"))text= (String) map.get(key);
                    if(key.equals("comment_releasedata"))timebe= (LocalDateTime) map.get(key);
                    if(key.equals("comment_update"))timeen= (LocalDateTime) map.get(key);
                    if(key.equals("comment_agreesum"))agree= (int) map.get(key);
                    if(key.equals("comment_againstsum"))disagree=(int)map.get(key);
                    if(key.equals("comment_user"))user=(String)map.get(key);
                    if(key.equals("comment_name"))name= (String) map.get(key);
                }
            }
            JOptionPane.showMessageDialog(frame,"id:"+id+"\n"+"文章名为:"+name+"\n作者:"+user+"\n内容:"+text+"\n赞同数"+agree+"\n反对数"+disagree+"\n创建时间:"+timebe+"\n最后修改时间"+timeen);
        }
    }
}
